package zxj.baidu.map.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;

import zxj.baidu.map.domain.BaiduMapPoi;
import zxj.baidu.map.domain.param.BaiduMapPoiParam;
import zxj.baidu.map.service.BaiduMapPoiService;

/**
 * 百度地图POI Controller
 *
 * @author zhuxuejiang
 */
@RestController()
@RequestMapping(value = "/poi")
public class BaiduMapPoiController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaiduMapPoiController.class);

    @Autowired
    private BaiduMapPoiService baiduMapPoiService;

    /**
     * 查询省份列表
     *
     * @return 省份列表
     */
    @GetMapping(value = "/getProvinces")
    public List<String> getProvinces() {
        return baiduMapPoiService.selectProvinceList();
    }

    /**
     * 查询城市列表
     *
     * @param province 省份
     * @return 城市列表
     */
    @GetMapping(value = "/getCities/{province}")
    public List<String> getCities(@PathVariable("province") String province) {
        return baiduMapPoiService.selectCityList(province);
    }

    /**
     * 查询区县列表
     *
     * @param city 城市
     * @return 区县列表
     */
    @GetMapping(value = "/getAreas/{city}")
    public List<String> getAreas(@PathVariable("city") String city) {
        return baiduMapPoiService.selectAreaList(city);
    }

    /**
     * 分页查询百度地图POI
     *
     * @param param 查询参数
     * @return 分页查询结果
     */
    @PostMapping(value = "/queryByPage")
    public Map<String, Object> queryByPage(@RequestBody BaiduMapPoiParam param) {
        Map<String, Object> result = new HashMap<>();
        Page<BaiduMapPoi> page = baiduMapPoiService.selectByPage(param);
        result.put("total", page.getTotal());
        result.put("tableData", page.getResult());
        return result;
    }

    /**
     * 查询百度地图POI列表
     *
     * @param param 查询参数
     * @return 百度地图POI列表
     */
    @PostMapping(value = "/list")
    public List<BaiduMapPoi> list(@RequestBody BaiduMapPoiParam param) {
        return baiduMapPoiService.selectList(param);
    }

}
